import {
	createApp
} from 'vue'
import {
	createPinia
} from 'pinia'
import './style.css'
import './assets/css/frank.scss'
import 'element-plus/dist/index.css'
import piniaPluginPersist from 'pinia-plugin-persist'
import App from './App.vue'
import router from './router/routes'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import ElementPlus from 'element-plus'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
import _axios from './utils/api/axios'
import _storage from './utils/storage'
import _common from './utils/common'
import _config from '../config/env.js'
import debounceClickDirective from './utils/debounce';
import introduceHint from './utils/introduceHint'
import ComponentAutoRegister from "./utils/ComponentAutoRegister"

// 自定义表单-start
import VForm3 from 'vform3-builds' //引入VForm 3库
import 'vform3-builds/dist/designer.style.css' //引入VForm3样式
// 自定义表单-end


const pinia = createPinia()
pinia.use(piniaPluginPersist)

const app = createApp(App)

// element ui icon图标循环注册
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
	app.component(key, component)
}

// 全局参数
app.config.globalProperties._http = _axios
app.config.globalProperties._storage = _storage
app.config.globalProperties._common = _common
app.config.globalProperties._config = _config
router.beforeEach((to, from, next) => {
	try {
		next()
	} catch (e) {
		window.location.href = "https://so.csdn.net/so/search?q=" + e.message
	}
});
app.directive('debounce', debounceClickDirective);
// app.directive('introduce', introduceHint);
// 挂载
new ComponentAutoRegister(app,
	import.meta.glob('@/components/**/*.vue'));
app.use(ElementPlus, {
	locale: zhCn,
})
app.use(router)
app.use(pinia)
app.use(VForm3) //全局注册VForm 3(同时注册了v-form-designer和v-form-render组件)
app.mount('#app')